// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'
import qs from 'qs'
import layer from 'vue-layer'
import App from './App'
import router from './router'
import store from './store'
import moment from 'moment'
// Vue.prototype.layer = axios
import './assets/css/reset.css'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import  VueQuillEditor from 'vue-quill-editor'
// require styles 引入样式
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
let Base64 = require('js-base64').Base64;
/**
 * 拦截器
 */
axios.defaults.retry = 3;
axios.defaults.retryDelay =10000;
let bol = true
axios.interceptors.response.use(undefined, function axiosRetryInterceptor(err) {
 var config = err.config;
 if(!config || !config.retry) return Promise.reject(err);
 config.__retryCount = config.__retryCount || 0;
 if(config.__retryCount >= config.retry) {
  if(bol) {
    alert('服务器连接失败，请刷新后重试!')
    bol = false
  }
  setTimeout( res => {
    bol = true
  },3000)
  return Promise.reject(err);
 }
 config.__retryCount += 1;
 var backoff = new Promise(function(resolve) {
  setTimeout(function() {
   resolve();
  }, config.retryDelay || 1);
 });
 return backoff.then(function() {
   
  return axios(config);
 });
});

Vue.use(VueQuillEditor)
import VueCookie from 'vue-cookie'
Vue.config.productionTip = false
// axios.defaults.baseURL = 'https://sharespace.cloudjoyclub.com//service/api'
axios.defaults.baseURL = 'http://114.116.100.38/service/api';
Vue.prototype.axios = axios
Vue.prototype.qs = qs
Vue.prototype.$layer = layer(Vue);
Vue.prototype.base64 = Base64;
Vue.prototype.$moment = moment;
Vue.prototype.encodeJson = ( val ) => {
	return Base64.encode ( JSON.stringify ( val ));
};
Vue.prototype.decodeJson = ( val ) => {
	return JSON.parse ( Base64.decode ( val ));
};
// Vue.use(axios)
Vue.use(Vuex)
Vue.use(ElementUI);
Vue.use ( VueCookie );

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
